<#include  "/common/mysql.ftl">
<#list doc.entitymodel.entity as entity>
<#if entity.@entity_name=object()>
/*${entity.@title}(T_${entity.@entity_name})*/
DROP TABLE IF EXISTS `t_${entity.@entity_name}`;
commit;
CREATE TABLE `T_${entity.@entity_name}`(
	<#list entity.field as field>
	`${field.@name}` <@fieldToSqlType field=field/><#if field.@notnull?size!=0><#if field.@notnull="yes"> NOT NULL</#if></#if> COMMENT '${field.@label}',
	</#list>
	PRIMARY KEY (<#list entity.prim_key as primkey>`${primkey.@field}`<#if primkey_has_next>,</#if></#list>)<#rt>
<#list entity.relation as rel><#rt>
<#if (rel.@column?if_exists?size>0)>,<#lt>
 	KEY `FK_${entity.@entity_name?upper_case}_${rel.@column?upper_case}` (`${rel.@column}`),
	CONSTRAINT `FK_${entity.@entity_name?upper_case}_${rel.@column?upper_case}` FOREIGN KEY (`${rel.@column}`) REFERENCES <#if (rel.@ref?if_exists?size>0)>`T_${rel.@ref}`<#else>`T_${rel.@type}`</#if> (`${rel.@property_ref}`)
</#if>
</#list>
   );
 ALTER TABLE  `T_${entity.@entity_name}` COMMENT = '${entity.@description}';
<#break/>
</#if>
</#list>  



